package me.helllp.dake.common.base;

import lombok.Getter;
import lombok.Setter;
import me.helllp.dake.common.exception.DakeErrorEnum;

/**
 * 所有接口返回的基类
 *
 * @param <T> 数据
 */
@Getter
@Setter
public class BaseResult<T> {
    /**
     * 返回结构的错误码
     */
    private String code;

    /**
     * 返回结构的信息
     */
    private String msg;

    /**
     * 返回结构的数据
     */
    private T data;

    public static <T> BaseResult<T> result(String code, String msg, T data) {
        BaseResult<T> retData = new BaseResult<>();
        retData.setCode(code);
        retData.setMsg(msg);
        retData.setData(data);
        return retData;
    }

    public static <T> BaseResult<T> fail(String msg) {
        return BaseResult.result(DakeErrorEnum.NORMAL_ERROR.getCode(), msg, null);
    }

    public static <T> BaseResult<T> result(DakeErrorEnum errorEnum) {
        return BaseResult.result(errorEnum.getCode(), "", null);
    }

    public static <T> BaseResult<T> success(T data) {
        return result(DakeErrorEnum.NORMAL.getCode(), "", data);
    }
}
